<?php
class CategoryModel extends Model {
	protected $tableName='category';
	
	/**
	 * 选择顶级分类
	 *
	 */
	public function selcate($pid=0){
		$sql='select * from category where pid=0';
		$res=mysql_query($sql);
		$name=array();
		while ($row=mysql_fetch_assoc($res)) {
			$name[]=$row;
		}
		return $name;
	}
	/**
	 * 删除分类，及其子类
	 *
	 */
	public function catedel($id){
		$sql='delete from '.$this->tableName.' where id='.$id.' or pid='.$id;
		$res=mysql_query($sql);
		if($res){
			return mysql_affected_rows();
		}
		else{
			return $res;
		}
	}
	
	
	public function selpid($id){
		$sql='select pid from category where id='.$id;
		$res=mysql_query($sql);
		if($res){
			$row=mysql_fetch_assoc($res);
			return $row['pid'];
		}else{
			return $res;
		}
		
	}
}
?>